#ifndef __SIMULATION_H
#define __SIMULATION_H

#include <list>
#include "sprite.h"
#include "collisionStrategy.h"
#include "spriteManager.h"
#include "constraint.h"
#include "contact.h"

class Simulator
{
	public:
		static Simulator &getInstance();
		~Simulator();
		void step();
		void setTimeStep();
		void addConstraint(Constraint *d);
		void removeConstraint(Constraint *d);
		void removeConstraints(Sprite *s);
		void setContactListener(ContactListener *cl);
		void restart();
		void setPlayer(Player *p);

	private:
		Simulator();
		Simulator(const Simulator &);
		Simulator &operator=(const Simulator&);

		void symplecticEuler();
		void clearForces();
		void satisfyConstraints();

		void setTimeStep(float t);

		void checkCollisions();
		void checkObjectCollision(Sprite &d);
		void executeCollisionStrategy(Sprite &d1, Sprite &d2);

		SpriteManager &spriteManager;
		CollisionStrategy *collisionStrategy;
		CollisionStrategy *collisionResponse;
		std::list<Constraint *> constraints;
		ContactListener *contactListener;
		Vector2f g;
		float timeStep;
		Player *player;
};

#endif // !__SIMULATION_H
